// running
// gcc -std=c99 -o crub crubic.c

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

typedef unsigned char byte;

//#define CSIZE 3
#define CSIZE 2

struct CUBE{
// layout: side1 - lines, then side2 - lines, side3, ...
/*
	side layout:
	4
	0123
	5

*/
  byte vals[6][CSIZE][CSIZE];
};

void print_cube(struct CUBE c){
  for( int line=0; line<CSIZE; line++ ){
    for( int side=0; side<6; side++ ){
        //int base = side*CSIZE*CSIZE + line*CSIZE;
        if( CSIZE==3 ){
          printf("%2x %2x %2x  ", (int)(c.vals[side][line][0]), (int)(c.vals[side][line][1]), (int)(c.vals[side][line][2]));
        }else if( CSIZE==2 ){
          printf("%1x%1x ", (int)(c.vals[side][line][0]), (int)(c.vals[side][line][1]) );
          if( side==3 ) printf("T");
          if( side==4 ) printf("B");
        }
    }
    printf("\n");
  }
}

block_rotate(struct CUBE *c, int[][] blocks){

}

struct CUBE rotate2x2(struct CUBE c, int op){
    struct CUBE ret = c;

    // face turn left
    int[][][] face_turn_left = {
      "000 001 011 010",
      "410-411 100-110 501-500 311-301"
    }

    block_rotate(&c, new int[])

    ret.vals[0][0][0] = c.vals[0][0][1];
    ret.vals[0][0][1] = c.vals[0][1][1];
    ret.vals[0][1][0] = c.vals[0][0][0];
    ret.vals[0][1][1] = c.vals[0][1][0];

... hm much work, error prone, but movements are limited and in loops, can we use that
to declare more high-level?

    return ret;
}

struct CUBE mkCube(){
  struct CUBE c;

  for( int side=0; side<6; side++ ){
    for( int line=0; line<CSIZE; line++ ){
        for( int row=0; row<CSIZE; row++ ){
            c.vals[side][line][row] = side+1;
        }
    }
  }
  return c;
}

void main(){
    //struct CUBE cubea;
    //print_cube(cubea);

    struct CUBE cubeb = mkCube();
    //printf("\nat 0 = %d\n", (int)(cubeb.vals[0]));
    print_cube(cubeb);

    printf("hello\n");
    printf("size of int %ld \n", sizeof(int));
    printf("size of byte %ld \n", sizeof(byte));
    printf("size of cubea %ld \n", sizeof(cubeb));
    int f = open("crubic.c", O_RDONLY);
    printf("my file handle %d \n", f);
    int f2 = open("crub", O_RDONLY);
    printf("my file handle2 %d \n", f2);

}
